#!/usr/bin/env python
import RPi.GPIO as GPIO
import time

ObstaclePin = 11

def setup():
    GPIO.setmode(GPIO.BOARD)       # Numbers GPIOs by physical location
    GPIO.setup(ObstaclePin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

def loop():
    while True:
        if (False == GPIO.input(ObstaclePin)):  #当检测到障碍物时，输出低电平信号
            print("Detected Barrier!")
        else :
            print("****Nothing!******")
        time.sleep(1)
            

def destroy():
    GPIO.cleanup()                     # Release resource

if __name__ == '__main__':     # Program start from here
    setup()
    try:
        loop()
    except KeyboardInterrupt:  # When 'Ctrl+C' is pressed, the child program destroy() will be  executed.
        destroy()


